﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class Web_Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //try
        //{
            pagerefresh();
            pagerefresh();
        //}
        //catch (Exception ee)
        //{
        //    string msg = ee.ToString();
        //    string[] arr = msg.Split('.');
        //    string message1 = arr[1].ToString();
        //    Response.Redirect("404.aspx?msg='" + message1 + "'");
        //}
    }

    public void pagerefresh()
    {
     //try
     //  {
        #region Set the position to the grid in pageload
        if (IsPostBack)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "hash", "location.hash = '#companel';", true);
        }
        #endregion

            #region Check Distributors Rank Using Bonus Table

             if (Session["user"] != null)
                {
                string uid = Session["user"].ToString();
                Bestlife.ERP.Entities.E_Profile pro = Bestlife.ERP.DataAccess.DistributerAC.getallprofileinfo(uid);
            
                 #region Get data from the Distributor Table
            Name.Text = pro.Title1 + pro.Name1;  
            AboutMe.Text = "";
            Contact.Text = pro.Contact1;
            URL.Text = pro.URL1;
            Email.Text = pro.Email1;
            Address1.Text = pro.Address11;
            Address2.Text = pro.Address21;
            Address3.Text = pro.Address31;
            CPV.Text = "Cumalative Point Value  =  " + pro.CPV1;
            if (pro.PPV1 == "0.00")
            {
                PPV.Text = "Personal Point Value    =   " + pro.StorePV1;
            }
            else
            {
                PPV.Text = "Personal Point Value    =   " + pro.PPV1;
            }
            #endregion
            

            if (pro.Rank1.Equals("0"))
            {
                Rank.Text = "Not Ranked Yet";
            }
            else if (pro.Rank1.Equals("1"))
            {
                Rank.Text = "Distributor";
            }
            else if (pro.Rank1.Equals("2"))
            {
                Rank.Text = "5% Presenter";
            }
            else if (pro.Rank1.Equals("3"))
            {
                Rank.Text = "10% Presenter";
            }
            else if (pro.Rank1.Equals("4"))
            {
                Rank.Text = "15 Presenter";
            }
            else if (pro.Rank1.Equals("5"))
            {
                Rank.Text = "Agent";
            }
            else if (pro.Rank1.Equals("6"))
            {
                Rank.Text = "Ruby";
            }
            else if (pro.Rank1.Equals("7"))
            {
                Rank.Text = "Diamond";
            }
            else if (pro.Rank1.Equals("8"))
            {
                Rank.Text = "Senior Diamond";
            }
            else if (pro.Rank1.Equals("9"))
            {
                Rank.Text = "Senior Executive Diamond";
            }
            else if (pro.Rank1.Equals("10"))
            {
                Rank.Text = "Crown Diamond";
            }
            else if (pro.Rank1.Equals("11"))
            {
                Rank.Text = "2Crown Diamond";
            }
            else if (pro.Rank1.Equals("12"))
            {
                Rank.Text = "3Crown Diamond";
            }
            else if (pro.Rank1.Equals("14"))
            {
                Rank.Text = "4Crown Diamond";
            }
            else if (pro.Rank1.Equals("15"))
            {
                Rank.Text = "5Crown Diamond";
            }        
            
        #endregion
            }
            else Response.Redirect("Login.aspx");
            

       //}
       //catch (Exception ee)
       //{
       //    //string msg = ee.ToString();
       //    //string[] arr = msg.Split('.');
       //    //string message1 = arr[1].ToString();
       //    //Response.Redirect("404.aspx?msg='" + message1 + "'");
       //}
    }



    protected void  Button3_Click(object sender, EventArgs e)
    {
   
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
       // string id = "0";
        Bestlife.ERP.DataAccess.DistributerAC blabla = new Bestlife.ERP.DataAccess.DistributerAC();
        string id=blabla.historycheck(Session["user"].ToString(),DropDownListMonth.SelectedValue.ToString(), DropDownListYear.SelectedValue.ToString());
        if (id != "")
        {
            Label1.ForeColor = System.Drawing.Color.Green;
            Label1.Text = "Commission is " + id + " for " + DropDownListMonth.SelectedItem.ToString();
        }
        else
        {
            Label1.ForeColor = System.Drawing.Color.Red;
            Label1.Text = "No Commission for " + DropDownListMonth.SelectedItem.ToString();
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Bestlife.ERP.DataAccess.DistributerAC bvcount = new Bestlife.ERP.DataAccess.DistributerAC();
        string id=bvcount.bvcheck(Session["user"].ToString(),BVDropDownListMonth.SelectedValue.ToString(),BVDropDownListYear.SelectedValue.ToString());
        if (id != "")
        {
            Label2.ForeColor = System.Drawing.Color.Green;
            Label2.Text = "Business Value is " + id + " for " + BVDropDownListMonth.SelectedItem.ToString();
        }
        else 
        {
            Label2.ForeColor = System.Drawing.Color.Red;
            Label2.Text = "No Business Value for " + BVDropDownListMonth.SelectedItem.ToString();
        }

    }

    //protected void Chart1_Load(object sender, EventArgs e)
    //{
    //    //try
    //    //{

    //        DataTable dt = default(DataTable);
    //        dt = CreateDataTable();


    //        //Set the DataSource property of the Chart control to the DataTabel
    //        Chart1.DataSource = dt;

    //        //Give two columns of data to Y-axle
    //        Chart1.Series[0].YValueMembers = "TotalCommition";

    //        //Set the X-axle as date value
    //        Chart1.Series[0].XValueMember = "Month";

    //        //Bind the Chart control with the setting above
    //        Chart1.DataBind();
    //    //}
    //    //catch (Exception ee) 
        
    //    //{
    //    //    string msg = ee.ToString();
    //    //    string[] arr = msg.Split('.');
    //    //    string message1 = arr[1].ToString();
    //    //    Response.Redirect("404.aspx?msg='" + message1 + "'");
    //    //}
    //}

    //private DataTable CreateDataTable()
    //{

    //        List<Bestlife.ERP.Entities.E_Chart> to_chart = new List<Bestlife.ERP.Entities.E_Chart>();

    //        Bestlife.ERP.DataAccess.DistributerAC commition = new Bestlife.ERP.DataAccess.DistributerAC();
    //        to_chart = commition.chart(Session["user"].ToString(), DropDownList1.SelectedValue.ToString());
    //        //Create a DataTable as the data source of the Chart control
    //        DataTable dt = new DataTable();

    //        //Add three columns to the DataTable
    //        dt.Columns.Add("Month");
    //        dt.Columns.Add("TotalCommition");

    //        foreach (Bestlife.ERP.Entities.E_Chart ch in to_chart)
    //        {
    //            DataRow dr;
    //            dr = dt.NewRow();
    //            dr["Month"] = ch.H_month;
    //            dr["TotalCommition"] = ch.H_comm;
    //            dt.Rows.Add(dr);
    //        }
    //        return dt;
    //}

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //try
        //{
      //      CreateDataTable();
        //}
        //catch (Exception ee)
        //{
        //    string msg = ee.ToString();
        //    string[] arr = msg.Split('.');
        //    string message1 = arr[1].ToString();
        //    Response.Redirect("404.aspx?msg='" + message1 + "'");
        //}
    }
}